package com.android.le.myspinnerview;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.android.view.spinnerleview.NiceSpinner;
import com.android.view.spinnerleview.SpinnerTextFormatter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    NiceSpinner spinner;
    private List<ArgumentsModel> argumentsModels = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        spinner = (NiceSpinner) findViewById(R.id.sp_con);
        SpinnerTextFormatter textFormatter = new SpinnerTextFormatter<ArgumentsModel>() {
            @Override
            public String format(ArgumentsModel argumentsModel) {
                return argumentsModel.getArgumentsTitle();
            }
        };
        spinner.setSpinnerTextFormatter(textFormatter);
        spinner.setSelectedTextFormatter(textFormatter);
        spinner.attachDataSource(getArgumentsModels());

    }

    public List<ArgumentsModel> getArgumentsModels() {
        if (argumentsModels.size() == 0) {
            String[] maps = new String[]{"模糊查询", "档案ID", "编号", "档案名称", "描述", "载体", "状况", "密级", "来源", "类别", "所属", "归档者"};
            String[] fields = new String[]{"", "id", "code", "name", "description", "nature", "status", "secret", "source", "sort", "belong", "collator"};
            for (int i = 0; i < maps.length; i++) {
                ArgumentsModel model = new ArgumentsModel(maps[i], fields[i]);
                argumentsModels.add(model);
            }
        }
        return argumentsModels;
    }

}